﻿@using KPIS.GERP.Models
@model Asset
@{
    ViewBag.Title = "ระบบควบคุมและจำหน่ายพัสดุ"; ViewBag.Descr = "ทะเบียนควบคุมพัสดุ"; 
    if (Model != null) { ViewBag.AssetId = Model.AssetId; }
}

@using (Html.BeginForm("UploadPictureAsset", "ParcelControlAssetList", new { AssetId = Model.AssetId }, FormMethod.Post
                       , new { enctype = "multipart/form-data", @class = "form-horizontal" }))
{
    @Html.AntiForgeryToken()

    <div class="block-button-menu-above">
        
        @Html.ActionLink("กลับไปหน้าแสดงข้อมูล", "IndexAsset", new { AssetId = Model.AssetId }
            , new { @class = "btn btn-gray button-standard-width btn-small", role = "button" })
        
        @if (Model.RecordStatus != "D")
        {
            @Html.ButtonSubmit()

            @Html.ActionLink("ยกเลิก", "IndexAsset", new {AssetId = Model.AssetId}
                , new {@class = "btn btn-danger button-standard-width btn-small", role = "button"})

            @:&nbsp;&nbsp;&nbsp;&nbsp;

            @Html.ActionLink("ลบ", "DeleteAsset", new {id = Model.AssetId}
                , new {@class = "btn btn-danger button-standard-width btn-small", role = "button"})
        }
        
        @Html.ActionLink("พิมพ์ Barcode", "GenderateBarcode", new { AssetId = Model.AssetId, AssetCode = Model.AssetCode, AssetName = Model.AssetName }
            , new { @class = "btn btn-gray button-standard-width btn-small", role = "button" })
    </div>
    
    @Html.ValidationSummary()
    @Html.Partial("_EditorAssertDetails")
    
}

@section scripts
{
    <script>
        $("form").submit(function(e) {
            e.preventDefault();
            var currentForm = this;
            bootbox.confirm('บันทึกข้อมูลใช่หรือไม่', function(result) {
                if (result) {
                    currentForm.submit();
                }
            });
        });

        $(function() {

            $("#ResItemId").change(function() {
                var id = $('#ResItemId').val();
                $.getJSON('@Url.Action("GetResItemProperty")/?resitemid=' + id, function(data) {
                    $('#ResGrpId').val(data.ResGrpId);
                    $('#ResSubGrpId').val(data.ResSubGrpId);
                    $('#UnitId').val(data.UnitId);
                    $("#ResGrpId").trigger("liszt:updated");
                    $("#ResSubGrpId").trigger("liszt:updated");
                });
            });

            $("#DepreciationTypeId").change(function() {
                var id = $('#DepreciationTypeId').val();
                $.getJSON('@Url.Action("GetDepreciationTypeProperty")/?DpTypeId=' + id, function (data) {
                    $('#MasDepreciationType_DpRateYear').val(data.DpRateYear);
                });
            });
        });

        function reloadDropdown() {
            alert('กำลังโหลดข้อมูล กรุณารอสักครู่');
            $.getJSON('@Url.Action("GetResItems")/', function(data) {
                $.each(data, function(i, result) {
                    var text = "<option value='" + result.ResItemId + "'  >" + result.ResItemName + "</option>";
                    $('#ResItemId').append(text);
                });
            }).always(function() {
                $('#ResItemId').trigger('liszt:updated');
            });
        }

    </script>
}